package central;
import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Random;

import GUI.Ventana;

import control_monitor.Monitor;


public class Generador_piezas_distribuido extends Thread{
	private static int portr1=14000;
	private static int portr2=14001;
	private static int portr3=14002;
	private static int portm1=17000;
	private static int portm2=17001;
	private static int portm3=17002;
	private static int portm4=17003;
	
	Ventana gui;
	Monitor monit;
	
	int demora;
	
public Generador_piezas_distribuido(Monitor _monit, Ventana _gui, int _demora){
	 monit = _monit;
	 gui = _gui;
	 demora = _demora;
}

public void Generarpieza_A(){
	Thread pieza=new Thread(new pieza_A(monit,portr1,portr2,portr3,portm1,portm2, gui));
	pieza.start();
}

public void Generarpieza_B(){
	Thread piezab=new Thread(new pieza_B(monit,portr2,portm3,portm4, gui));
	piezab.start();
}

public void Generarpieza_C(){
	Thread piezac=new Thread(new pieza_C(monit,portr1,portr2,portm2,portm3,portm4, gui));
	piezac.start();
}

public void run()
{
	while(true)
	{
		int priori = new Random().nextInt(100);
		if(priori < 33){
			Generarpieza_A();
		}
		else if( priori >= 33 && priori < 66)
		{
			Generarpieza_B();
		}
		else{
			Generarpieza_C();
		}
		
		
		try {
			Thread.sleep(demora);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}


}
